package com.github.niefy.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description:
 * @Company：乙盟信息
 * @Author: jiangheng
 * @Date: 2022/1/23 14:26
 * @Version 1.0
 */
@Component
public class ServerConfig {


    static int serverPort;

    static String path;
    @Value("${server.port}")
    public void setServerPort(Integer serverPort){
        ServerConfig.serverPort = serverPort;
    }
    @Value("${server.servlet.context-path}")
    public void setPath(String path){
        ServerConfig.path = path;
    }
    public static String getUrl() {
        InetAddress address = null;
        try {
            address = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        //return "http://"+address.getHostAddress() +":"+ServerConfig.serverPort+"/"+ServerConfig.path;
        return "http://127.0.0.1:"+ServerConfig.serverPort+"/"+ServerConfig.path;
    }

}
